package com.atguigu.jxc.controller.base;

import com.atguigu.jxc.domain.ServiceVO;
import com.atguigu.jxc.domain.SuccessCode;
import com.atguigu.jxc.entity.Customer;
import com.atguigu.jxc.entity.Goods;
import com.atguigu.jxc.entity.GoodsType;
import com.atguigu.jxc.service.GoodsTypeService;
import com.google.gson.Gson;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;

@RestController
public class GoodsTypeController {
    @Autowired
    private GoodsTypeService goodsTypeService;

    //加载商品分类列表
    @PostMapping("/goodsType/loadGoodsType")
    public String loadGoodsType(){
        List<Map<String, Object>> maps = goodsTypeService.getAllGoodsType(-1);
        //把list转为string
        Gson gson = new Gson();
        String json = gson.toJson(maps);
        System.out.println(json);
        return json;
    }

    //查询单位列表
    @PostMapping("/unit/list")
    public Map<String, Object> getGoodsUnit() {
        return this.goodsTypeService.getGoodsUnit();
    }

    //查询所有的商品信息
    @PostMapping("/goods/list")
    public Map<String, Object> goodsList(Integer page,
                                         Integer rows,
                                         String goodsName,
                                         Integer goodsTypeId) {

        return goodsTypeService.goodsList(page, rows, goodsName, goodsTypeId);
    }

    //新增分类
    @PostMapping("/goodsType/save")//http://localhost:8080/goodsType/save
    public ServiceVO saveType(String goodsTypeName,Integer pId) {

        return goodsTypeService.saveType(goodsTypeName, pId);

    }
    //删除分类
    @PostMapping("/goodsType/delete")//http://localhost:8080/goodsType/delete
    public ServiceVO deleteType(Integer  goodsTypeId){
        return goodsTypeService.deleteType(goodsTypeId);
    }
}